package com.yzf.demo.demo.io;

import java.io.*;

/**
 * Created by 于占峰 on 2020/4/14/014.
 */
public class ObjectDemo {

    public static void main(String[] args) {

/*        DemoBean demoBean = new DemoBean("小明",18);//存储在内存中

        try {
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("G:/DemoBean.class"));
            //将对象序列化存储到本地硬盘
            objectOutputStream.writeObject(demoBean);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        try {
            // 反序列化 读取本地的class文件
            ObjectInputStream objectIntputStream = new ObjectInputStream(new FileInputStream("G:/DemoBean.class"));
            //调用readObject 将文件序列化为实例对象存入内存
            DemoBean demoBean = (DemoBean) objectIntputStream.readObject();
            System.out.println(demoBean);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
